package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.i18n.I18Bundle;
import com.github.aloxc.plugin.restplus.component.Dialog;
import com.github.aloxc.plugin.restplus.component.HistoryForm;
import com.github.aloxc.plugin.restplus.navigator.RestServiceDetail;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
 *
 * @author leero
 */
public class HistoryMouseListener extends MouseAdapter {
    private Project project;
    private RestServiceDetail restServiceDetail;
    private boolean allHistory;

    public HistoryMouseListener(RestServiceDetail restServiceDetail,boolean allHistory){
        this.restServiceDetail = restServiceDetail;
        this.allHistory = allHistory;
    }
    @Override
    public void mouseClicked(MouseEvent e) {
        HistoryForm historyForm = new HistoryForm(restServiceDetail,allHistory,restServiceDetail.getParentName());
        int height = 640;
        int width = 900;
        historyForm.setMaximumSize(new Dimension(width,height));
        historyForm.setMinimumSize(new Dimension(width,height));
        historyForm.setPreferredSize(new Dimension(width,height));

        Dialog dialog = new Dialog(null, historyForm,
                new Dimension(width,height),
                new Dimension(width,height),
                new Dimension(width,height),
                IconLoader.getIcon("/icons/history.png"),
                allHistory ? I18Bundle.getMessage("com.github.aloxc.plugin.restplus.history.title").replace("(%s)","") :
                String.format(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.history.title"),restServiceDetail.getUrl())
        );
        dialog.setVisible(true);
    }


}
